<!--填报竣工-->
<template>
  <div class="do-common-task pending-task">
    <el-form
        ref="TcForm2"
        label-position="left"
        label-width="1.5rem"
        :model="Form"
    >
      <el-row>
        <tc-form2 :rules="rules" :form="Form">
        </tc-form2>
        <el-col :span="24" class="text-center mar-20">
          <el-button type="primary" size="medium" @click="validate"  >保存</el-button>
          <el-button size="medium" @click="closeFun">取消</el-button>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import TcForm2 from "@/components/public/TcForm2";
import CustOrderService from "@/api/order/CustOrderService";
import requestUtil from '@/utils/requestEnc';
import {mapState} from 'vuex';
import custOrderDetail from '@/mixins/custorder/custOrderDetail';
import refreshList from "@/mixins/custorder/refreshList";
let completeDate = function(rule, value,callback){
    let nowDate = new Date();
    let year = nowDate.getFullYear();
    let month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
    let day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
    let dateStr = year + "-" + month + "-" + day+" 00:00:00";
    const now = new Date(dateStr).getTime()
    let valueS = value+" 00:00:00";
    const _value = new Date(valueS).getTime()
    if (_value > now ) {
        callback(new Error('完成日期不能大于当天'));
    } else {
        callback();
    }
}
export default {
  name: "DoCommonTask",
  mixins: [custOrderDetail,refreshList],
  data() {
    return {
      Form: {
        // "11541-141000034": {
        //   type: 'Ipt',
        //   name: '流水号',
        //   colId: "CUST_SO_NUMBER",
        //   colType: "C",
        //   tableName: "ORDER_ITEM",
        //   fieldId: "CUST_SO_NUMBER",
        //   oldVal:'',
        //   attrRoleCd: "0",
        //   value: "",
        //   id: "11541-141000034",
        //   disabled: true,
        //   show: true,
        //   span: 6
        // },
        "11541-141000049": {
          type: 'Ipt',
          name: '任务名称',
          colId: "TASK_NAME",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "TASK_NAME",
          oldVal:'',
          attrRoleCd: "0",
          value: "全程报竣",
          id: "11541-141000049",
          disabled: true,
          show: true,
          span: 6
        },
        "11541-141000050": {
          type: 'Ipt',
          name: '产品名称',
          colId: "PRODUCT_NAME",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "PRODUCT_NAME",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "11541-141000050",
          disabled: true,
          show: true,
          span: 6,
        },
        "6491-100013275": {
          "name": "签字状态",
          "type": "select",
          "attrRoleCd": "0",
          "colId": "100013275",
          "colType": "T",
          "tableName": "ORDER_TASK_ATTR",
          "fieldId": "ASSIGN_STS",
          "value": "",
          "id": "6491-100013275",
          "options": [{"label": "客户签字", "value": 3055001}, {"label": "客户经理代客户签字", "value": 3055002}, {"label": "客户和客户经理均不签字", "value": 3055003}],
          "required": false,
          "show": true,
          "span": 6,
          marginRight: '25%'
        },
        "11541-100010013": {
          type: 'Ipt',
          name: '本地专线号',
          colId: "ACC_NUM",
          colType: "C",
          tableName: "ORD_PROD_INST",
          fieldId: "ACC_NBR",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "11541-100010013",
          show: true,
          span: 6
        },
        "11541-100011191": {
          type: 'Ipt',
          name: '运维网号',
          colId: "100011191",
          colType: "T",
          tableName: "ORD_PROD_INST_ATTR",
          fieldId: "VPN_NET_NBR",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "11541-100011191",
          show: true,
          span: 6,
        },
        "11541-141000046": {
          name: '完成情况',
          type: 'select',
          attrRoleCd: "0",
          colId: "RESULT",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "RESULT",
          value: "50250001",
          id: "11541-141000046",
          options: [{label: '完成', value: '50250001'}, {label: '未完成', value: '50250002'}],
          required: true,
          show: true,
          span: 6,
          marginRight: '25%'
        },
        "11541-100013415": {
          type: 'date',
          name: '完成日期',
          attrRoleCd: "0",
          colId: "TASK_ACT_DATE",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "TASK_ACT_DATE",
          value: "",
          id: "11541-100013415",
          show: true,
          span: 6,
        },
        "11541-141000047": {
          type: 'date',
          name: '要求完成日期',
          colId: "TASK_REQ_DATE",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "TASK_REQ_DATE",
          oldVal:'',
          attrRoleCd: "0",
          value: this.$util.dateFormat(new Date(), "yyyy-MM-dd"),
          id: "11541-141000047",
          disabled: true,
          show: true,
          span: 6,
        },
        "11541-100012377": {
          type: 'Ipt',
          name: '填报人',
          colId: "USER_NAME",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "USER_NAME",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "11541-100012377",
          readonly: true,
          show: true,
          span: 6,
          marginRight:'25%'
        },
        "11541-100012440": {
          type: 'date',
          name: '填报日期',
          attrRoleCd: "0",
          colId: "TASK_OPR_DATE",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "TASK_OPR_DATE",
          value: "",
          id: "11541-100012440",
          show: true,
          required: true,
          readonly: true,
          span: 6,
        },
        "11541-141000045": {
          type: 'Ipt',
          name: '联系电话',
          colId: "LINK_TEL",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "LINK_TEL",
          oldVal:'',
          attrRoleCd: "0",
          value: "",
          id: "11541-141000045",
          readonly: true,
          show: true,
          span: 6,
        },
        "11541-100012342": {
          type: 'textarea',
          name: '备注',
          attrRoleCd: "0",
          colId: "TASK_COMMENT",
          colType: "C",
          tableName: "ORDER_TASK",
          fieldId: "TASK_COMMENT",
          value: "",
          id: "11541-100012342",
          show: true,
          span: 20,
          marginRight: '25%'
        },
      },
      odtals:null,
      rules: {
        "11541-100013415": [
          { required: true, message: "完成日期不能为空", trigger: "change" },
            { validator: completeDate, trigger: "change" },
        ],
         "11541-141000046": [
          { required: true, message: "完成情况不能为空", trigger: "change" },
        ],
      }
    }
  },
  props: {
    ODKInfo: {
      type: Object
    },
    CTOInfo: {
      type: [Object,Array]
    }
  },
  mounted() {
  },
  created() {
    // this.getStatValue();
    this.getCustomerOrderDetail(this.Form,this.CTOInfo,this.ODKInfo);
    this.Form['11541-100012377'].value=this.user.staffName;
    this.Form['11541-100012440'].value=this.$util.dateFormat(new Date(), "yyyy-MM-dd");
    this.Form['11541-100012611'].value=this.$util.dateFormat(new Date(), "yyyy-MM-dd");
    this.Form['11541-141000047'].value=this.$util.dateFormat(new Date(), "yyyy-MM-dd");
  },
  components: {
    TcForm2
  },
  computed:{
    ...mapState('user',['user']),
    ...mapState('orders',['orderPosInfo'])
  },
  methods: {
     validate(){
      
      this.$refs['TcForm2'].validate((valid) => {
        
        if (valid) {
          this.submitFun();
        } else {
          
          return false;
        }
      });
    },
    // async getStatValue(){
    //
    // },
    async submitFun(){
      let base={
        userName: this.user.staffName,
        userId: this.user.staffId,
        orgId: this.user.orgId,
        actType: 'MOD',
        oneOrmany:'one'
      };
      let {userId,orgId} = base,
          {orderItemSeqs,custSoNumber,orderItemId,orderItemIds,custId} = this.CTOInfo,
          {taskId,activityId,processInstId,orderAuditId} = this.ODKInfo;
      
      
      let param = requestUtil.paramEnc(this.Form,Object.assign(this.ODKInfo,this.CTOInfo,base,this.odtals));
      let allParam = {orderAuditId,orderItemIds,custId,orderItemSeqs,custSoNumber,orderItemId,activityId,processInstId,userId,orgId,taskId,...base,...param};
      
      const result = await CustOrderService.saveCompletion(allParam);
      try {
        if(result.meta.resultCode == 0){
          this.$message({
            type: 'success',
            message: '保存成功!'
          });
          this.eventDoSearch();
          this.$emit('update:show',false);
        }else{
          this.$message({
            showClose: true,
            message: result.meta.resultMsg,
            type: 'error'
          });
        }
      } catch {
        this.$message({
          showClose: true,
          message: 'code:'+result.code+'  msg:'+result.msg,
          type: 'error'
        });
      }
    },
    closeFun(){
      this.$emit('update:show',false)
    }
  }
}
</script>

<style lang="scss" scoped>
.do-common-task{
  height: 84vh;
  overflow-y: auto;
}
</style>
